package com.example.newstudent.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.newstudent.dao.lessonDao;
import com.example.newstudent.dao.optional_courseDao;
import com.example.newstudent.entity.lesson;
import com.example.newstudent.entity.optional_course;
import com.example.newstudent.service.optional_courseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

@Service
public class optional_courseImpl implements optional_courseService {
    @Autowired
    optional_courseDao optional_courseDao;
    @Autowired
    lessonDao lessonDao;

    @Override
    public List<optional_course> display(String id) {
        int n = 0;
        QueryWrapper<lesson> lessonQueryWrapper = new QueryWrapper<>();
        lessonQueryWrapper.eq("studentid",id);
        List<lesson> lessons = lessonDao.selectList(lessonQueryWrapper);
        List<optional_course> optional_courses = optional_courseDao.selectList(null);
        List<optional_course> optional_courses1 = new ArrayList<>();
        for (int i = 0; i < optional_courses.size(); i++) {
            n = 0 ;
            for (int j = 0; j < lessons.size(); j++) {
                if (!Objects.equals(optional_courses.get(i).getWeeks(), lessons.get(j).getWeeks()) ||
                        optional_courses.get(i).getDay() != lessons.get(j).getDay() ||
                        optional_courses.get(i).getSection() != lessons.get(j).getSection() ) {
                    n++;}
            }
            if (n == lessons.size()) {
                optional_courses1.add(optional_courses.get(i));
            }
        }
        System.out.println(optional_courses1);
        return optional_courses1;
    }

    @Override
    public List<optional_course> optional() {
        return optional_courseDao.selectList(null);
    }
}
